package main.java.sales;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * SalesMapper
 *
 * @author zhangyimin
 * @version 1.0
 * @date 2018-11-07 上午9:41
 */
public class SalesMapper extends Mapper<LongWritable, Text, Text, DoubleWritable> {


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
//        13,987,1998-01-10,3,999,1,1232.16
        String[] fields = value.toString().split(",");
        String dateStr = fields[2].substring(0, 4);
//        Date date= DateUtil.parse(dateStr);
//        dateStr=DateUtil.format(date,"yyyy");
        Double amout = Double.valueOf(fields[6]);
        context.write(new Text(dateStr), new DoubleWritable(amout));
    }
}
